package com.meeting.meetingroom_api.service;

import com.meeting.meetingroom_api.dto.BookingCreateDto;
import com.meeting.meetingroom_api.dto.BookingDto;
import com.meeting.meetingroom_api.dto.BookingQueryDto;
import com.meeting.meetingroom_api.entity.Booking;
import com.meeting.meetingroom_api.enums.BookingStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.List;

public interface BookingService {
    BookingDto createBooking(BookingCreateDto createDto, Integer customerId); 
    BookingDto getBookingById(Integer bookingId);
    BookingDto getTimeOutBookById(Integer bookingId);
    BookingDto getBookingByIdAndCustomerId(Integer bookingId, Integer customerId); // For customer to view their own
    Page<BookingDto> findBookings(BookingQueryDto queryDto, Pageable pageable);
    List<BookingDto> getBookingsByCustomerId(Integer customerId);
    List<BookingDto> getBookingsByRoomId(Integer roomId);
    BookingDto updateBookingStatus(Integer bookingId, BookingStatus newStatus, Integer employeeIdIfApplicable); // employeeId for logging who changed status
    // cancelBooking will likely be a more complex operation involving Cancellation entity and rules
    // void processPaymentTimeoutBookings(); // For a scheduled task
    Page<BookingDto> getBookingsByCustomerId(BookingStatus status, Integer customerId, Pageable pageable);
    Page<BookingDto> getBookingsByRoomId(Integer roomId, Pageable pageable);
    
    // 获取客户可以取消的预订（提前24小时以上的确认预订）
    Page<BookingDto> getCancellableBookingsByCustomerId(Integer customerId, Pageable pageable);

    /**
     * 设置会议室为维护状态
     * @param bookingId 预订ID
     * @param employeeId 员工ID
     * @param maintenanceNotes 维护说明
     * @return 更新后的预订信息
     */
    BookingDto setRoomMaintenance(Integer bookingId, Integer employeeId, String maintenanceNotes);

    /**
     * 确认客户入场
     * @param bookingId 预订ID
     * @param employeeId 员工ID
     * @return 更新后的预订信息
     */
    BookingDto checkIn(Integer bookingId, Integer employeeId);

    /**
     * 确认客户离场
     * @param bookingId 预订ID
     * @param employeeId 员工ID
     * @param roomConditionNotes 会议室使用情况备注
     * @return 更新后的预订信息
     */
    BookingDto checkOut(Integer bookingId, Integer employeeId, String roomConditionNotes);

    /**
     * 完成会议室维护
     * @param bookingId 预订ID
     * @param employeeId 员工ID
     * @return 更新后的预订信息
     */
    BookingDto completeMaintenance(Integer bookingId, Integer employeeId);

    BookingDto getBookingByActiveRoomId(Integer roomId);

    Page<BookingDto> getCompletedBookings(Integer id, Pageable pageable);

    BookingDto cancelPendingPay(Integer bookingId);

    List<Booking> findByStatusAndPaymentDeadlineBetween(BookingStatus bookingStatus, LocalDateTime fiveMinutesAgo, LocalDateTime now);

    void handleTimeOut(Booking booking);

    List<Booking> findExpiredBookings();
    
    void handleExpiredBooking(Booking booking);
    
    void processExpiredBookings();
}